<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->jiqilog_status;
$tabs=array(
	array('op'=>'list','title'=>'全部记录'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if($_RQ['id'] || $_RQ['team_id']){
		$team_id=$_RQ['id']?:$_RQ['team_id'];
		$paiweilogs=$this->model('team')->getpaiweilogs(array('id'=>$team_id));
		$list=array();
		foreach($paiweilogs as $log){
			$list=array_merge($list,$log['logs']);
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	if(!$team_id){
		$list=pdo_getslice('jy_paiweifee_team_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	}
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['shmember']=cfc('core')->member_show($item['p_mid']);
			if($team_id){
				$item['team']=pdo_get('jy_paiweifee_team',array('uniacid'=>$_SESSION['uniacid'],'id'=>$team_id));
				$item['createtime']=strtotime($item['createtime']);
			}else{
				$item['team']=pdo_get('jy_paiweifee_team',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['myteam_id']));
			}
			$item['bossmember']=cfc('core')->member_show($item['team']['mid']);
			$item['isnum']=$this->model('team')->get_isnum($item['team']['id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'list'=>array(
			array('name'=>'bossmember','title'=>'开团人','type'=>'member'),
			array('name'=>'myteam_id','title'=>'我团ID','type'=>'string'),
			array('name'=>'p_teamid','title'=>'上级团ID','type'=>'string'),
			array('name'=>'member','title'=>'参与人','type'=>'member'),
			array('name'=>'team.level','title'=>'团层级','type'=>'string'),
			array('name'=>'team.num','title'=>'每层人数','type'=>'string'),
			//array('name'=>'isnum','title'=>'已参与人数','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'teamid','title'=>'团ID','type'=>'string','width'=>15),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_paiweifee_team_log',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_paiweifee_team_log',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
